<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <!-- 
    computed的写法和methods完全一致

    计算属性中的方法在使用时不需要写参数

    1 当表达式过于复杂时
    2 从原本data中生成新的数据时
  -->

  <div id="app">
    {{msg.split('').reverse().join('')}}
    <br>
    {{reverseMsg}}

    <hr>
    <h3>所有电影</h3>
    <ul>
      <li v-for="movie in movies">{{movie.title}}</li>
    </ul>
    <h3>已观看电影</h3>
    <ul>
      <!-- <li v-for="movie in movies" v-if="movie.isWatched">{{movie.title}}</li> -->
      <li v-for="movie in isWatchedMovies()">{{movie.title}}</li>
    </ul>
    <h3>未观看电影</h3>
    <ul>
      <!-- <li v-for="movie in movies" v-if="!movie.isWatched">{{movie.title}}</li> -->
      <li v-for="movie in notWatchedMovies">{{movie.title}}</li>
    </ul>
  </div>

  <script src="./vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        msg: 'Hello World',
        movies: [{
          title:'电影名1',
          isWatched: true
        },{
          title:'电影名2',
          isWatched: true
        },{
          title:'电影名3',
          isWatched: true
        },{
          title:'电影名4',
          isWatched: false
        },{
          title:'电影名5',
          isWatched: true
        },{
          title:'电影名6',
          isWatched: false
        },{
          title:'电影名7',
          isWatched: false
        }]
      },
      methods: {
        isWatchedMovies () {
          return this.movies.filter(movie => movie.isWatched)
        },
      },
      computed: {
        reverseMsg () {
          return this.msg.split('').reverse().join('')
        },
        /* isWatchedMovies () {
          return this.movies.filter(movie => movie.isWatched)
        }, */
        notWatchedMovies () {
          return this.movies.filter(movie => !movie.isWatched)
        }
      }
    })
  </script>
</body>
</html>